package com.zpark.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

import java.util.Locale;

public class I18nLocaleConfig {

    @Configuration
    public class I18nlocaleConfig {
        @Bean
        public LocaleResolver localeResolver(){
            SessionLocaleResolver resolver = new SessionLocaleResolver();
            resolver.setDefaultLocale(Locale.SIMPLIFIED_CHINESE);
            return resolver;
        }
        //拦截器，请求参数为lang
        @Bean
        public WebMvcConfigurer localeInterceptor(){
            return new WebMvcConfigurer() {
                @Override
                public void addInterceptors(InterceptorRegistry registry) {
                    LocaleChangeInterceptor interceptor  = new LocaleChangeInterceptor();
                    interceptor.setParamName("lang");
                    registry.addInterceptor(interceptor);
                }
            };
        }

    }

}
